package com.example.chirdrenserver.Utils;

import lombok.Data;

import java.io.Serializable;

/**
 * 后端统一返回结果
 * @param <T>
 */
@Data
public class Result<T> implements Serializable {

    private  Integer type; //状态码
    private Integer code; //编码：0成功，1和其它数字为失败
    private  String state; //状态，直观展示
    private String message; //信息
    private Long Id; //数据
    private T data; //数据

    private  int count ;


    public static <T> Result<T> success() {
        Result<T> result = new Result<T>();
        result.code = 0;
        result.state="ture";
        result.message="成功";
        return result;
    }

    public static <T> Result<T> success(T object) {
        Result<T> result = new Result<T>();
        result.code = 0;
        result.state="ture";
        result.message="成功";
        result.data=object;
        return result;
    }

    public static <T> Result<T> success(String message) {
        Result<T> result = new Result<T>();
        result.code = 0;
        result.state="ture";
        result.message=message;
        return result;
    }
    public static <T> Result<T> success(T object,int count) {
        Result<T> result = new Result<T>();
        result.data = object;
        result.code = 0;
        result.state="ture";
        result.message="成功";
        result.count=count;
        return result;
    }

    public static <T> Result<T> success(T object,long id) {
        Result<T> result = new Result<T>();
        result.data = object;
        result.code = 0;
        result.state="ture";
        result.message="成功";
        result.Id=id;
        return result;
    }
    public static <T> Result<T> error(String msg) {
        Result result = new Result();
        result.message = msg;
        result.code = 1;
        result.state="false";
        return result;
    }

}
